using System;
using UnityEngine;

namespace EventBehaviorTree
{
    [Serializable]
    public class InstantCondition : EventNode
    {
        private Func<bool> Condition;
        public InstantCondition(Func<bool> condition) { SetCondition(condition); }
        public InstantCondition() : this(null) { }

        public override void SetCoroutineStarter(MonoBehaviour coroutineStarter) { }

        public void SetCondition(Func<bool> condition)
        {
            Condition = condition == null ? delegate { return true; } : condition;
        }

        public override void NodeEvent(NodeMsg nodeMessage)
        {
            if (nodeMessage == NodeMsg.Start)
            {
                if (Condition()) SuperiorNodeEvent(NodeMsg.Succeed);
                else SuperiorNodeEvent(NodeMsg.Fail);
            }
        }
    }
}
